package com.isoftstone.merchant.controller.feeUser;

import com.isoftstone.bank.controller.base.BaseController;
import com.isoftstone.common.Page;
import com.isoftstone.common.Tidings;
import com.isoftstone.common.service.ISysUserService;
import com.isoftstone.merchant.entity.bind.MBind;
import com.isoftstone.merchant.entity.feeUser.MFeeUser;
import com.isoftstone.merchant.entity.mdept.MDept;
import com.isoftstone.merchant.entity.notify.BNotify;
import com.isoftstone.merchant.entity.notify.BNotifyDetail;
import com.isoftstone.merchant.service.bind.BindService;
import com.isoftstone.merchant.service.feeUser.FeeUserService;
import com.isoftstone.merchant.service.mdept.impl.MdeptService;
import com.isoftstone.merchant.service.merchant.MerchantService;
import com.isoftstone.merchant.service.notice.impl.NotifyService;
import com.isoftstone.util.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLDecoder;
import java.util.*;

/**
 * Created by as on 2017/12/4.
 * 缴费用户controller
 */
@Controller
public class FeeUserController extends BaseController {
    @Autowired
    private FeeUserService feeUserService;
    @Autowired
    private MdeptService mdeptService;
    @Autowired
    private NotifyService notifyService;
    @Autowired
    private MerchantService merchantService;
    @Autowired
    private BindService bindService;
    @Autowired
    private ISysUserService sysUserService;

    /*
    * 缴费用户列表
    * */
    @RequiresPermissions("mms-menu.002.001")
    @RequestMapping("merchant/feeUser/getFeeUserList")
    public ModelAndView toFeeUserListPage() {
        ModelAndView md = new ModelAndView();
        md.setViewName("merchant/payFee_save/payFee_save");
        return md;
    }

    @RequestMapping(value = "merchant/feeUser/getFeeUserList2", method = RequestMethod.POST)
    @ResponseBody
    public Object getFeeUserListPage(Page page) {
        PageData pd = this.getPageData();
        Tidings<List<MFeeUser>> tidings = new Tidings<List<MFeeUser>>();
        String userId=this.getUser().getUserid();
        List<MDept>deptids=null;
        try {
            deptids=feeUserService.getalldeptByUserId(userId);//得到用户对应的deptid
            if(deptids!=null){
                List<String>list=new ArrayList<String>();
                for(MDept mDept1:deptids){
                    list.add(mDept1.getDeptId());
                }
                pd.put("deptIds",list);//看到当前用户部门的缴费用户
            }
            String treeId = pd.getString("treeId");//部门树id串
            String keywords = pd.getString("searchContent");//搜索内容
            String search = pd.getString("search");//如果是搜索的用户带值过来标记
            String corpId = this.getUser().getCorpId();
            pd.put("corpId", corpId);
            pd.put("deptId", "");
            pd.put("keywords", "");
            pd.put("statu","0");
            List<MFeeUser> feeUserSearch = new ArrayList<MFeeUser>();
            List<MFeeUser> feeUsertList0 = new ArrayList<MFeeUser>();
            List<MFeeUser> feeUserList1 = new ArrayList<MFeeUser>();
            List<String >treeIdss=new ArrayList<String>();
            if (StringUtils.isNotBlank(treeId) && StringUtils.isNotBlank(keywords)) {
                keywords = URLDecoder.decode(keywords, "UTF-8");
                pd.put("keywords", keywords);
                String treeIds[] = treeId.split(",");
                for (String str : treeIds) {
                    treeIdss.add(str);
                }
                pd.put("treeids",treeIdss);
                page.setPd(pd);
                feeUsertList0 = feeUserService.getFeeUserlistPage(page);
                feeUserList1=feeUserService.getFeeUserlistPageDept(feeUsertList0);
            } else if (StringUtils.isNotBlank(treeId) && StringUtils.isBlank(keywords)) {
                String treeIds[] = treeId.split(",");
                for (String str : treeIds) {
                    treeIdss.add(str);
                }
                pd.put("treeids",treeIdss);
                page.setPd(pd);
                feeUsertList0 = feeUserService.getFeeUserlistPage(page);
                feeUserList1=feeUserService.getFeeUserlistPageDept(feeUsertList0);
            } else if (StringUtils.isBlank(treeId) && StringUtils.isNotBlank(keywords)) {
                keywords = URLDecoder.decode(keywords, "UTF-8");
                pd.put("keywords", keywords);
                page.setPd(pd);
                feeUserSearch = feeUserService.getFeeUserlistPage(page);
                if (feeUserSearch != null) {
                    for (MFeeUser feeUser : feeUserSearch) {
                        feeUsertList0.add(feeUser);
                    }
                }
                feeUserList1=feeUserService.getFeeUserlistPageDept(feeUsertList0);
            } else {
                page.setPd(pd);
                feeUsertList0 = feeUserService.getFeeUserlistPage(page);
                feeUserList1=feeUserService.getFeeUserlistPageDept(feeUsertList0);
            }
            List<String> feeUserIds = new ArrayList<String>();
            if (feeUserList1 != null) {
                for (MFeeUser feeUser : feeUserList1) {
                    feeUserIds.add(feeUser.getFeeUserId());
                }
            }
            tidings.setT(feeUserList1).setPage(page);
            tidings.setStatus(Const.SUCCESS);
            if (StringUtils.isNotBlank(search)) {
                this.getSession().setAttribute("feeUserIds", feeUserIds);
            } else {
                this.getSession().setAttribute("feeUserIds", null);
            }
        } catch (Exception e) {
            tidings.setStatus(Const.ERROR);
            tidings.setMsg("数据异常！");
            e.printStackTrace();
        }
        return tidings;
    }

    /*
    * 缴费用户删除
    * */
    @RequestMapping("merchant/feeUser/deleteFeeUser")
    @ResponseBody
    public Object deleteuser() {
        PageData pd = this.getPageData();
        String feeUserId = pd.getString("feeuserId");
        Tidings<String> tidings = new Tidings<String>();
        try {
            String name="";
            String feeuserids[]=feeUserId.split(",");
            if(feeuserids!=null) {
                for (String str : feeuserids) {
                    String feeStatus = "04";//未缴费m_fee_userm_merchant pay_status
                    String status = "1";//删除payment中status不等于1（有效的）
                    Integer feeUserCount = feeUserService.getFeeUserCountFromPayment(str, feeStatus, status);
                    MFeeUser mFeeUser = feeUserService.getFeeUserById(str);
                    if (feeUserCount != 0) {
                        name += mFeeUser.getFeeUserName() + "  ";
                    }
                }
            }
            if(name!=null&&name!=""){
                StringUtils.replaceAll(name,"null"," ");
                tidings.setStatus(Const.SUCCESS);
                tidings.setMsg(name+"有待缴费项目不能删除！");
                return tidings;
            }else{
                for(String str:feeuserids) {
                    Integer in = feeUserService.deleteFeeUserCountFromPayment(str);//删除缴费主表该用户数据
                    feeUserService.deleteFeeUserById(str);
                }
//                MFeeUser mFeeUser=new MFeeUser();
//                mFeeUser.setStatus(status);
//                mFeeUser.setFeeUserId(str);
//                feeUserService.updateFeeUser(mFeeUser);
                tidings.setStatus(Const.SUCCESS);
                tidings.setMsg("删除"+feeuserids.length+"条成功！");
                return tidings;
          }
        } catch (Exception e) {
            tidings.setStatus(Const.SUCCESS);
            tidings.setMsg("删除失败！");
            e.printStackTrace();
        }
        return tidings;
    }
    /*
     * 缴费用户审核
     * status 1 是修改 2 是审批
     * */
    @RequestMapping("merchant/feeUser/examineFeeUser")
    @ResponseBody
    public Object examineFeeUser() {
        PageData pd = this.getPageData();
        String userId=this.getUser().getUserid();
        String corpId=this.getUser().getCorpId();
        String feeUserId = pd.getString("feeuserId");
        String status = "1";
        pd.put("status", status);
        pd.put("feeUserId", feeUserId);
        Tidings<String> tidings = new Tidings<String>();
        try {
            Integer updateStatus = feeUserService.updateFeeUserStatus(pd);
            MFeeUser mFeeUser=feeUserService.getFeeUserById(feeUserId);
            if (updateStatus > 0) {
                BNotify bNotify=new BNotify();
                String noticeId=UuidUtil.getNumFormatUUID();
                Long  notifyId=Long.parseLong(noticeId);
                bNotify.setNotifySeq(notifyId);
                String content="您的缴费用户"+mFeeUser.getFeeUserName()+"("+mFeeUser.getFeeId()+")"+"申请已经通过复核！";
                bNotify.setNotifyContext(content);
                bNotify.setCreateDate(new Date());
                bNotify.setCreator(userId);
                bNotify.setPhoneType(Const.n0002);
                bNotify.setStatus(Const.send);//1正常
                bNotify.setCreatorType("02");//02为缴费单位管理人员创建
                bNotify.setNotifyType("04");//04为缴费单位缴费用户
                bNotify.setCreatorUnit(corpId);//商户ID
                int i =notifyService.saveNotify(bNotify);
                if(i>0){
                    BNotifyDetail bNotifyDetail=new BNotifyDetail();
                    bNotifyDetail.setNotify_id(notifyId);
                    bNotifyDetail.setUser_id(feeUserId);
                    bNotifyDetail.setUser_type("03");//缴费单位缴费用户
                    bNotifyDetail.setIs_read("0");//未读
                    notifyService.saveNotifyDetail(bNotifyDetail);
                    tidings.setStatus(Const.SUCCESS);
                    tidings.setMsg("审批成功！");
                }
            }
        } catch (Exception e) {
            tidings.setStatus(Const.SUCCESS);
            tidings.setMsg("审批失败！");
            e.printStackTrace();
        }
        return tidings;
    }
    @RequestMapping("merchant/feeUser/checkFeeId")
    @ResponseBody
    public Object checkFeeId(){
        Tidings<String>tidings=new Tidings<String>();
        tidings.setStatus(Const.SUCCESS);
        String cropId = this.getUser().getCorpId();//商户主键
        String feeId=this.getRequest().getParameter("feeId");
        try {
            if(StringUtils.isNotBlank(feeId)) {
                Integer mFeeId = feeUserService.getFeeUserId(feeId, cropId);
                if (mFeeId == 1) {
                    tidings.setMsg("缴费编号已经存在");
                }
            }else {
                tidings.setMsg(" ");
            }
        } catch (Exception e) {
            e.printStackTrace();
            tidings.setMsg("数据异常");
        }
        return tidings;
    }
    /**
     * 到添加或者页面
     */
    @RequestMapping("merchant/feeUser/addOrSaveFeeUser")
    @ResponseBody
    public Object saveOrupdateFeeUser(MFeeUser mFuser) {
        Tidings<String> tidings = new Tidings<String>();
        String userId = this.getUser().getUserid();//创建(或更新)人主键
        String cropId = this.getUser().getCorpId();//商户主键
        MBind mBind=new MBind();
        if (mFuser.getSaveOrUpdate() == null || "".equals(mFuser.getSaveOrUpdate())) {//添加
            String feeUserId = UuidUtil.getNumFormatUUID();
           // String bMindId=UuidUtil.getNumFormatUUID();
            mFuser.setCorpId(cropId);
            mFuser.setCreator(userId);
            mFuser.setFeeUserId(feeUserId);
            //后台添加缴费用户存入m_bind
//            mBind.setSeqId(Long.parseLong(bMindId));
//            mBind.setFeeUserId(feeUserId);
//            mBind.setStatus("0");//1生效0解约
//            mBind.setCorpId(cropId);
//            mBind.setCreator(userId);
//            mBind.setCreateDate(new Date());
//            mBind.setOpenAccount(mFuser.getTelNo());//默认给手机号
        }
        try {
            if (StringUtils.isBlank(mFuser.getFeeId())) {
                tidings.setStatus(Const.SUCCESS);
                tidings.setMsg("请填写缴费编号！");
            } else if (StringUtils.isNotBlank(mFuser.getFeeId())) {
                Integer mFeeUser = feeUserService.getFeeUserId(mFuser.getFeeId(),cropId);
                if (mFeeUser != 0 && "".equals(mFuser.getSaveOrUpdate())) {
                    tidings.setStatus(Const.SUCCESS);
                    tidings.setMsg("缴费编号已经存在！");
                } else {
                    if (mFuser.getSaveOrUpdate() == null || "".equals(mFuser.getSaveOrUpdate())) {
                        mFuser.setCreateDate(new Date());
                        mFuser.setStatus("1");
//                        bindService.saveBind(mBind);
                        feeUserService.saveFeeUserByExcel(mFuser);
                        tidings.setStatus(Const.SUCCESS);
                        tidings.setMsg("保存成功！");
                    } else {//修改页面
                        Integer mFeeUser1 = feeUserService.getFeeUserId2(mFuser.getFeeId(), mFuser.getFeeUserId());
                        Integer mfeeUser2=feeUserService.getFeeUserId(mFuser.getFeeId(),cropId);
                        if (mFeeUser1 == 1||mfeeUser2==0) {
                            mFuser.setUpdateDate(new Date());
                            mFuser.setUpdator(userId);
                            if("男".equals(mFuser.getSex())||"1".equals(mFuser.getSex())){
                                mFuser.setSex("1");
                            }else{
                                mFuser.setSex("0");
                            }
                            feeUserService.updateFeeUser(mFuser);
                            tidings.setStatus(Const.SUCCESS);
                            tidings.setMsg("更新成功！");
                        } else {
                            tidings.setStatus(Const.SUCCESS);
                            tidings.setMsg("缴费编号已经存在！");
                        }
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            tidings.setStatus(Const.ERROR);
            tidings.setMsg("操作失败！");
        }
        return tidings;
    }
    /*
    * 导出模板
    * */
    @RequestMapping("/merchant/feeUser/getExcelModel")
    public ModelAndView getExcelModel() {
        ModelAndView mv = new ModelAndView();
        Map<String, Object> dataMap = new HashMap<String, Object>();
        List<String> titles = new ArrayList<String>();
        titles.add("用户姓名");
        titles.add("缴费编号");
        titles.add("联系方式");
        titles.add("一级机构");
        titles.add("二级机构");
        titles.add("三级机构");
        titles.add("四级机构");
        titles.add("五级机构");
        titles.add("六级机构");
        titles.add("七级机构");
        titles.add("八级机构");
        titles.add("九级机构");
        titles.add("十级机构");
        titles.add("性别(男/女)");
        titles.add("身份证号");
        titles.add("家庭地址");
        titles.add("联系人");
        titles.add("联系电话");
        titles.add("备注1");
        titles.add("备注2");
        dataMap.put("titles", titles);
        PageData subpd = new PageData();
        subpd.put("var1", "");
        subpd.put("var2", "");
        subpd.put("var3", "");
        subpd.put("var4", "");
        subpd.put("var5", "");
        subpd.put("var6", "");
        subpd.put("var7", "");
        subpd.put("var8", "");
        subpd.put("var9", "");
        subpd.put("var10", "");
        subpd.put("var11", "");
        subpd.put("var12", "");
        subpd.put("var13", "");
        subpd.put("var14", "");
        subpd.put("var15", "");
        subpd.put("var16", "");
        subpd.put("var17", "");
        subpd.put("var18", "");
        subpd.put("var19", "");
        subpd.put("var20", "");
        List<PageData> subList = new ArrayList<PageData>();
        subList.add(subpd);
        dataMap.put("varList", subList);
        dataMap.put("name", "fee_user");
        dataMap.put("sheetName", "缴费人员");
        ObjectExcelView erv = new ObjectExcelView();                    //执行excel操作
        mv = new ModelAndView(erv, dataMap);
        return mv;
    }
    /*
    * 批量导出
    * */
    @RequestMapping("/merchant/feeUser/getExPort")
    public ModelAndView getExPort() {
        ModelAndView mv = new ModelAndView();
        Map<String, Object> dataMap = new HashMap<String, Object>();
        List<String> titles = new ArrayList<String>();
        titles.add("用户姓名");
        titles.add("缴费编号");
        titles.add("联系方式");
        titles.add("一级机构");
        titles.add("二级机构");
        titles.add("三级机构");
        titles.add("四级机构");
        titles.add("五级机构");
        titles.add("六级机构");
        titles.add("七级机构");
        titles.add("八级机构");
        titles.add("九级机构");
        titles.add("十级机构");
        titles.add("性别(男/女)");
        titles.add("身份证号");
        titles.add("家庭地址");
        titles.add("联系人");
        titles.add("联系电话");
        titles.add("备注1");
        titles.add("备注2");
        dataMap.put("titles", titles);
        List<PageData> subList = new ArrayList<PageData>();
        String cropId = this.getUser().getCorpId();
        PageData pd = this.getPageData();
        List<String> feeUserIds1 = (List<String>) this.getSession().getAttribute("feeUserIds");//如果是搜索的用户需要获取显示用户的ID
        String feeUserId = "";
        if (feeUserIds1 != null) {
            for (String feeid : feeUserIds1) {
                feeUserId += feeid + ",";
            }
            feeUserId = feeUserId.substring(0, feeUserId.length());
        }
        try {
            String cropName=merchantService.getCorpNameBycorIp(cropId);//商户名
            List<MFeeUser> allMFeeUser = new ArrayList<MFeeUser>();
            if (StringUtils.isNotBlank(feeUserId)) {
                String feeUserIds[] = feeUserId.split(",");
                Map<String,Object>map=new HashMap<String,Object>();
                for (int i = 0; i < feeUserIds.length; i++) {
                    map.put("cropId",cropId);
                    map.put("feeUserIds",feeUserIds[i]);
                    map.put("statu","0");
                    List<MFeeUser> MFeeUser = feeUserService.getExcelAllFeeUserList(map);
                    if(MFeeUser!=null) {
                        allMFeeUser.add(MFeeUser.get(0));
                    }
                }
            } else {
                Map<String,Object>map1=new HashMap<String,Object>();
                map1.put("cropId",cropId);
                map1.put("statu","0");
                String userId=this.getUser().getUserid();
                List<MDept>deptids=feeUserService.getalldeptByUserId(userId);//得到用户对应的deptid
                    if(deptids!=null){
                        List<String>list=new ArrayList<String>();
                        for(MDept mDept1:deptids){
                            list.add(mDept1.getDeptId());
                        }
                        map1.put("deptIds",list);//看到当前用户部门的缴费用户
                    }
                allMFeeUser = feeUserService.getExcelAllFeeUserList(map1);
            }
            for (MFeeUser mFeeUser : allMFeeUser) {
                mFeeUser.setCropName(cropName);
                MDept mDept = null;
                if(StringUtils.isNotBlank(mFeeUser.getDeptId())){
                    mDept= mdeptService.getDeptbyIdFeeUser(mFeeUser.getDeptId(), null);
                if (mDept != null) {
                    Integer level = mDept.getLevel();
                    if (level != null && level == 1) {
                        mFeeUser.setOneDept(mDept.getDeptName());
                    } else if (level != null && level == 2) {
                        mFeeUser.setTwoDept(mDept.getDeptName());
                        MDept mDept1 = mdeptService.getDeptbyIdFeeUser(null, mDept.getSuperDeptId());
                        mFeeUser.setOneDept(mDept1.getDeptName());
                    } else if (level != null && level == 3) {
                        mFeeUser.setThreeDept(mDept.getDeptName());
                        MDept mDept1 = mdeptService.getDeptbyIdFeeUser(null, mDept.getSuperDeptId());
                        mFeeUser.setTwoDept(mDept1.getDeptName());
                        MDept mDept2 = mdeptService.getDeptbyIdFeeUser(null, mDept1.getSuperDeptId());
                        mFeeUser.setOneDept(mDept2.getDeptName());
                    } else if (level != null && level == 4) {
                        mFeeUser.setFourDept(mDept.getDeptName());
                        MDept mDept1 = mdeptService.getDeptbyIdFeeUser(null, mDept.getSuperDeptId());
                        mFeeUser.setThreeDept(mDept1.getDeptName());
                        MDept mDept2 = mdeptService.getDeptbyIdFeeUser(null, mDept1.getSuperDeptId());
                        mFeeUser.setTwoDept(mDept2.getDeptName());
                        MDept mDept3 = mdeptService.getDeptbyIdFeeUser(null, mDept2.getSuperDeptId());
                        mFeeUser.setOneDept(mDept3.getDeptName());
                    } else if (level != null && level == 5) {
                        mFeeUser.setFiveDept(mDept.getDeptName());
                        MDept mDept1 = mdeptService.getDeptbyIdFeeUser(null, mDept.getSuperDeptId());
                        mFeeUser.setFourDept(mDept1.getDeptName());
                        MDept mDept2 = mdeptService.getDeptbyIdFeeUser(null, mDept1.getSuperDeptId());
                        mFeeUser.setThreeDept(mDept2.getDeptName());
                        MDept mDept3 = mdeptService.getDeptbyIdFeeUser(null, mDept2.getSuperDeptId());
                        mFeeUser.setTwoDept(mDept3.getDeptName());
                        MDept mDept4 = mdeptService.getDeptbyIdFeeUser(null, mDept3.getSuperDeptId());
                        mFeeUser.setOneDept(mDept4.getDeptName());
                    } else if (level != null && level == 6) {
                        mFeeUser.setSixDept(mDept.getDeptName());
                        MDept mDept1 = mdeptService.getDeptbyIdFeeUser(null, mDept.getSuperDeptId());
                        mFeeUser.setFiveDept(mDept1.getDeptName());
                        MDept mDept2 = mdeptService.getDeptbyIdFeeUser(null, mDept1.getSuperDeptId());
                        mFeeUser.setFourDept(mDept2.getDeptName());
                        MDept mDept3 = mdeptService.getDeptbyIdFeeUser(null, mDept2.getSuperDeptId());
                        mFeeUser.setThreeDept(mDept3.getDeptName());
                        MDept mDept4 = mdeptService.getDeptbyIdFeeUser(null, mDept3.getSuperDeptId());
                        mFeeUser.setTwoDept(mDept4.getDeptName());
                        MDept mDept5 = mdeptService.getDeptbyIdFeeUser(null, mDept4.getSuperDeptId());
                        mFeeUser.setOneDept(mDept5.getDeptName());
                    } else if (level != null && level == 7) {
                        mFeeUser.setSevenDept(mDept.getDeptName());
                        MDept mDept1 = mdeptService.getDeptbyIdFeeUser(null, mDept.getSuperDeptId());
                        mFeeUser.setSixDept(mDept1.getDeptName());
                        MDept mDept2 = mdeptService.getDeptbyIdFeeUser(null, mDept1.getSuperDeptId());
                        mFeeUser.setFiveDept(mDept2.getDeptName());
                        MDept mDept3 = mdeptService.getDeptbyIdFeeUser(null, mDept2.getSuperDeptId());
                        mFeeUser.setFourDept(mDept3.getDeptName());
                        MDept mDept4 = mdeptService.getDeptbyIdFeeUser(null, mDept3.getSuperDeptId());
                        mFeeUser.setThreeDept(mDept4.getDeptName());
                        MDept mDept5 = mdeptService.getDeptbyIdFeeUser(null, mDept4.getSuperDeptId());
                        mFeeUser.setTwoDept(mDept5.getDeptName());
                        MDept mDept6 = mdeptService.getDeptbyIdFeeUser(null, mDept5.getSuperDeptId());
                        mFeeUser.setOneDept(mDept6.getDeptName());
                    } else if (level != null && level == 8) {
                        mFeeUser.setEightDept(mDept.getDeptName());
                        MDept mDept1 = mdeptService.getDeptbyIdFeeUser(null, mDept.getSuperDeptId());
                        mFeeUser.setSevenDept(mDept1.getDeptName());
                        MDept mDept2 = mdeptService.getDeptbyIdFeeUser(null, mDept1.getSuperDeptId());
                        mFeeUser.setSixDept(mDept2.getDeptName());
                        MDept mDept3 = mdeptService.getDeptbyIdFeeUser(null, mDept2.getSuperDeptId());
                        mFeeUser.setFiveDept(mDept3.getDeptName());
                        MDept mDept4 = mdeptService.getDeptbyIdFeeUser(null, mDept3.getSuperDeptId());
                        mFeeUser.setFourDept(mDept4.getDeptName());
                        MDept mDept5 = mdeptService.getDeptbyIdFeeUser(null, mDept4.getSuperDeptId());
                        mFeeUser.setThreeDept(mDept5.getDeptName());
                        MDept mDept6 = mdeptService.getDeptbyIdFeeUser(null, mDept5.getSuperDeptId());
                        mFeeUser.setTwoDept(mDept6.getDeptName());
                        MDept mDept7 = mdeptService.getDeptbyIdFeeUser(null, mDept6.getSuperDeptId());
                        mFeeUser.setOneDept(mDept7.getDeptName());
                    } else if (level != null && level == 9) {
                        mFeeUser.setNineDept(mDept.getDeptName());
                        MDept mDept1 = mdeptService.getDeptbyIdFeeUser(null, mDept.getSuperDeptId());
                        mFeeUser.setEightDept(mDept1.getDeptName());
                        MDept mDept2 = mdeptService.getDeptbyIdFeeUser(null, mDept1.getSuperDeptId());
                        mFeeUser.setSevenDept(mDept2.getDeptName());
                        MDept mDept3 = mdeptService.getDeptbyIdFeeUser(null, mDept2.getSuperDeptId());
                        mFeeUser.setSixDept(mDept3.getDeptName());
                        MDept mDept4 = mdeptService.getDeptbyIdFeeUser(null, mDept3.getSuperDeptId());
                        mFeeUser.setFiveDept(mDept4.getDeptName());
                        MDept mDept5 = mdeptService.getDeptbyIdFeeUser(null, mDept4.getSuperDeptId());
                        mFeeUser.setFourDept(mDept5.getDeptName());
                        MDept mDept6 = mdeptService.getDeptbyIdFeeUser(null, mDept5.getSuperDeptId());
                        mFeeUser.setThreeDept(mDept6.getDeptName());
                        MDept mDept7 = mdeptService.getDeptbyIdFeeUser(null, mDept6.getSuperDeptId());
                        mFeeUser.setTwoDept(mDept7.getDeptName());
                        MDept mDept8 = mdeptService.getDeptbyIdFeeUser(null, mDept7.getSuperDeptId());
                        mFeeUser.setOneDept(mDept8.getDeptName());
                    } else if (level != null && level == 10) {
                        mFeeUser.setTenDept(mDept.getDeptName());
                        MDept mDept1 = mdeptService.getDeptbyIdFeeUser(null, mDept.getSuperDeptId());
                        mFeeUser.setNineDept(mDept1.getDeptName());
                        MDept mDept2 = mdeptService.getDeptbyIdFeeUser(null, mDept1.getSuperDeptId());
                        mFeeUser.setEightDept(mDept2.getDeptName());
                        MDept mDept3 = mdeptService.getDeptbyIdFeeUser(null, mDept2.getSuperDeptId());
                        mFeeUser.setSevenDept(mDept3.getDeptName());
                        MDept mDept4 = mdeptService.getDeptbyIdFeeUser(null, mDept3.getSuperDeptId());
                        mFeeUser.setSixDept(mDept4.getDeptName());
                        MDept mDept5 = mdeptService.getDeptbyIdFeeUser(null, mDept4.getSuperDeptId());
                        mFeeUser.setFiveDept(mDept5.getDeptName());
                        MDept mDept6 = mdeptService.getDeptbyIdFeeUser(null, mDept5.getSuperDeptId());
                        mFeeUser.setFourDept(mDept6.getDeptName());
                        MDept mDept7 = mdeptService.getDeptbyIdFeeUser(null, mDept6.getSuperDeptId());
                        mFeeUser.setThreeDept(mDept7.getDeptName());
                        MDept mDept8 = mdeptService.getDeptbyIdFeeUser(null, mDept7.getSuperDeptId());
                        mFeeUser.setTwoDept(mDept8.getDeptName());
                        MDept mDept9 = mdeptService.getDeptbyIdFeeUser(null, mDept8.getSuperDeptId());
                        mFeeUser.setOneDept(mDept9.getDeptName());
                    }
                }
                }
            }
            for (MFeeUser fUser : allMFeeUser) {
                PageData subpd = new PageData();
                subpd.put("var1", fUser.getFeeUserName());
                subpd.put("var2", fUser.getFeeId());
                subpd.put("var3", fUser.getTelNo());
                subpd.put("var4", fUser.getOneDept());
                subpd.put("var5", fUser.getTwoDept());
                subpd.put("var6", fUser.getThreeDept());
                subpd.put("var7", fUser.getFourDept());
                subpd.put("var8", fUser.getFiveDept());
                subpd.put("var9", fUser.getSixDept());
                subpd.put("var10", fUser.getSevenDept());
                subpd.put("var11", fUser.getEightDept());
                subpd.put("var12", fUser.getNineDept());
                subpd.put("var13", fUser.getTenDept());
                if (StringUtils.isNotBlank(fUser.getSex()) && "1".equals(fUser.getSex())) {
                    subpd.put("var14", "男");
                } else {
                    subpd.put("var14", "女");
                }
                subpd.put("var15", fUser.getCardId());
                subpd.put("var16", fUser.getAddr());
                subpd.put("var17", fUser.getLinkMan());
                subpd.put("var18", fUser.getLinkPhone());
                subpd.put("var19", fUser.getRemark1());
                subpd.put("var20", fUser.getRemark2());
                subList.add(subpd);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        dataMap.put("varList", subList);
        dataMap.put("name", "fee_user");
        dataMap.put("sheetName", "缴费人员");
        ObjectExcelView erv = new ObjectExcelView();
        mv = new ModelAndView(erv, dataMap);
        return mv;
    }
/*
* 批量导入
* */
    @RequestMapping(value = "/merchant/feeUserr/readdeptExcel",method =RequestMethod.POST,produces = {"text/html;charset=UTF-8"})
   // @ResponseBody
    public void readdeptExcel(@RequestParam(value = "file", required = false) MultipartFile file, HttpServletRequest request, HttpServletResponse response) {
        Tidings<List<MFeeUser>> tidings = new Tidings<>();
        String filePath = PathUtil.getClasspath() + Const.FILEPATHFILE;                                //文件上传路径
        int i = 0;
        //生成的文件名字
        String generatorFileName = "deptInfo" + UuidUtil.get32UUID();
        Map<String, Object> map = new HashMap<String, Object>();
        String cropId = this.getUser().getCorpId();
        String userId=this.getUser().getUserid();
        String fileName = null;
        try {
            fileName = FileUpload.fileUp(file, filePath, generatorFileName);
        } catch (Exception e) {
            e.printStackTrace();
        }
        String header = "用户姓名:feeUserName,缴费编号:feeId,联系方式:telNo,一级机构:oneDept,二级机构:twoDept,三级机构:threeDept,四级机构:fourDept," +
                "五级机构:fiveDept,六级机构:sixDept,七级机构:sevenDept,八级机构:eightDept,九级机构:nineDept,十级机构:tenDept,性别(男/女):sex,身份证号:cardId,家庭地址:addr," +
                "联系人:linkMan,备注1:remark1,备注2:remark2,联系电话:linkPhone";
        try {
            List<MFeeUser> deptsment = ExcelUtil.readXls(filePath + fileName, ExcelUtil.getMap(header), "com.isoftstone.merchant.entity.feeUser.MFeeUser");
           if(deptsment.size()==0||deptsment==null){
               tidings.setStatus(Const.ERROR);
               tidings.setMsg("请填写数据");
               throw new RuntimeException("请填写数据");
           }
            for (i = 0; i < deptsment.size(); i++) {
                MFeeUser mFeeUser = deptsment.get(i);
                if (XSSCheckUtil.checkXSS(mFeeUser.getFeeUserName())
                        || XSSCheckUtil.checkXSS(mFeeUser.getFeeId())
                        || XSSCheckUtil.checkXSS(mFeeUser.getTelNo())
                        || XSSCheckUtil.checkXSS(mFeeUser.getOneDept())
                        || XSSCheckUtil.checkXSS(mFeeUser.getTwoDept())
                        || XSSCheckUtil.checkXSS(mFeeUser.getThreeDept())
                        || XSSCheckUtil.checkXSS(mFeeUser.getFourDept())
                        || XSSCheckUtil.checkXSS(mFeeUser.getFiveDept())
                        || XSSCheckUtil.checkXSS(mFeeUser.getSixDept())
                        || XSSCheckUtil.checkXSS(mFeeUser.getSevenDept())
                        || XSSCheckUtil.checkXSS(mFeeUser.getEightDept())
                        || XSSCheckUtil.checkXSS(mFeeUser.getNineDept())
                        || XSSCheckUtil.checkXSS(mFeeUser.getTenDept())
                        || XSSCheckUtil.checkXSS(mFeeUser.getSex())
                        || XSSCheckUtil.checkXSS(mFeeUser.getCardId())
                        || XSSCheckUtil.checkXSS(mFeeUser.getAddr())
                        || XSSCheckUtil.checkXSS(mFeeUser.getLinkMan())
                        || XSSCheckUtil.checkXSS(mFeeUser.getRemark1())
                        || XSSCheckUtil.checkXSS(mFeeUser.getRemark2())
                        ) {
                    tidings.setStatus(Const.ERROR);
                    tidings.setMsg("第" + (i + 1) + "行数据异常，请检查后再次导入");
                    throw new RuntimeException("第" + (i + 1) + "行数据异常，请检查后再次导入");
                }
            }
            List<MFeeUser> mFeeUsers = new ArrayList<MFeeUser>();
            for (i = 0; i < deptsment.size(); i++) {
                MFeeUser mfeu = new MFeeUser();
                if (StringUtils.isBlank(deptsment.get(i).getFeeUserName())) {
                    tidings.setStatus(Const.ERROR);
                    tidings.setMsg("第" + (i + 1) + "行用户姓名不能为空，请检查后再次导入");
                    throw new RuntimeException("第" + (i + 1) + "行用户姓名不能为空，请检查后再次导入");
                } else {
                    mfeu.setFeeUserName(deptsment.get(i).getFeeUserName());
                }
                if (StringUtils.isBlank(deptsment.get(i).getFeeId())) {
                    tidings.setStatus(Const.ERROR);
                    tidings.setMsg("第" + (i + 1) + "行缴费编号不能为空，请检查后再次导入");
                    throw new RuntimeException("第" + (i + 1) + "行缴费编号不能为空，请检查后再次导入");
                } else {
                    Integer mf = feeUserService.getFeeUserId(deptsment.get(i).getFeeId(), cropId);//查询缴费编号是否存在
                    if (mf != 0) {
                        tidings.setStatus(Const.ERROR);
                        tidings.setMsg("第" + (i + 1) + "缴费编号已经存在，请检查后再次导入");
                        throw new RuntimeException("第" + (i + 1) + "缴费编号已经存在，请检查后再次导入");
                    } else {
                        mfeu.setFeeId(deptsment.get(i).getFeeId());
                    }
                }
                if (StringUtils.isNotBlank(deptsment.get(i).getTelNo())) {
                    if (StringUtils.isNumeric(deptsment.get(i).getTelNo())) {
                        mfeu.setTelNo(deptsment.get(i).getTelNo());
                    } else {
                        tidings.setStatus(Const.ERROR);
                        tidings.setMsg("第" + (i + 1) + "电话号码错误，请检查后再次导入");
                        throw new RuntimeException("第" + (i + 1) + "电话号码错误，请检查后再次导入");
                    }
                }
                if (StringUtils.isNotBlank(deptsment.get(i).getSex())) {
                    if ("男".equals(deptsment.get(i).getSex())) {
                        mfeu.setSex("1");
                    } else {
                        mfeu.setSex("0");
                    }
                }
                if (StringUtils.isNotBlank(deptsment.get(i).getCardId())) {
                    mfeu.setCardId(deptsment.get(i).getCardId());
                }
                if (StringUtils.isNotBlank(deptsment.get(i).getAddr())) {
                    mfeu.setAddr(deptsment.get(i).getAddr());
                }
                if (StringUtils.isNotBlank(deptsment.get(i).getLinkMan())) {
                    mfeu.setLinkMan(deptsment.get(i).getLinkMan());
                }
                if (StringUtils.isNotBlank(deptsment.get(i).getLinkPhone())) {
                    mfeu.setLinkPhone(deptsment.get(i).getLinkPhone());
                }
                if (StringUtils.isNotBlank(deptsment.get(i).getRemark1())) {
                    mfeu.setRemark1(deptsment.get(i).getRemark1());
                }
                if (StringUtils.isNotBlank(deptsment.get(i).getRemark2())) {
                    mfeu.setRemark2(deptsment.get(i).getRemark2());
                }
                List<MDept>deptids=null;
                List<List<MDept>>depts=null;//有几个deptid就有几条线
                deptids=feeUserService.getalldeptByUserId(userId);//得到用户对应的deptid
                depts=new ArrayList<List<MDept>>();//登录用户对应的部门
                if(deptids.size()>0) {
                    for (MDept mDept : deptids) {
                        List<MDept> mDepts = mdeptService.getUpAlltree(mDept.getDeptId());
                        depts.add(mDepts);
                    }
                }
                if(StringUtils.isBlank(deptsment.get(i).getOneDept())){
                    tidings.setStatus(Const.ERROR);
                    tidings.setMsg("第" + (i + 1) + "行请填写完整机构");
                    throw new RuntimeException("第" + (i + 1) + "行请填写完整机构");
                }
                if (   StringUtils.isNotBlank(deptsment.get(i).getOneDept())
                        &&StringUtils.isBlank(deptsment.get(i).getTwoDept())
                        && StringUtils.isBlank(deptsment.get(i).getThreeDept())
                        && StringUtils.isBlank(deptsment.get(i).getFourDept())
                        && StringUtils.isBlank(deptsment.get(i).getFiveDept())
                        && StringUtils.isBlank(deptsment.get(i).getSixDept())
                        && StringUtils.isBlank(deptsment.get(i).getSevenDept())
                        && StringUtils.isBlank(deptsment.get(i).getEightDept())
                        && StringUtils.isBlank(deptsment.get(i).getNineDept())
                        && StringUtils.isBlank(deptsment.get(i).getTenDept())) {
                    map.put("deptName", deptsment.get(i).getOneDept());
                    map.put("level", "1");
                    map.put("cropId", cropId);
                    List<MDept>list=null;//属于那条线
                    if(depts.size()>0){
                        for(List<MDept> mDepts:depts){
                            for(MDept mDept:mDepts){
                                String str=String.valueOf(mDept.getLevel());
                                if(str.equals("1")&&mDept.getDeptName().equals(deptsment.get(i).getOneDept())){
                                    list=mDepts;
                                    break;
                                }
                            }
                        }
                        if(list==null||list.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行当前管理员无此一级机构");
                            throw new RuntimeException("第" + (i + 1) + "行当前管理员无此一级机构");
                        }else{
                            int count=0;
                            for(MDept mDept:list){
                                if("2".equals(mDept.getLevel())){
                                    count+=1;
                                }
                            }
                            if(count!=0){
                                tidings.setStatus(Const.ERROR);
                                tidings.setMsg("第" + (i + 1) + "行选择末级机构");
                                throw new RuntimeException("第" + (i + 1) + "行选择末级机构");
                            }else{
                                for(MDept mDept:list){
                                    String str=String.valueOf(mDept.getLevel());
                                    if("1".equals(str)){
                                        mfeu.setDeptId(mDept.getDeptId());
                                    }
                                }
                            }
                        }
                    }else{
                        List<MDept> mDept = mdeptService.getDeptByNameAndLevel(map);//依据部门名称和等级查找是否存在此部门
                        if(mDept.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "无此一级机构");
                            throw new RuntimeException("第" + (i + 1) + "无此一级机构");
                        }
                        List<MDept> mDept1 = mdeptService.getsonDept(mDept.get(0).getDeptId());
                        if (mDept1.size() == 0 || mDept1 == null) {
                            mfeu.setDeptId(mDept.get(0).getDeptId());
                        } else {
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行请填写末级部门");
                            throw new RuntimeException("第" + (i + 1) + "行请填写末级部门");
                        }
                    }
                }else if (StringUtils.isNotBlank(deptsment.get(i).getOneDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getTwoDept())
                        && StringUtils.isBlank(deptsment.get(i).getThreeDept())
                        && StringUtils.isBlank(deptsment.get(i).getFourDept())
                        && StringUtils.isBlank(deptsment.get(i).getFiveDept())
                        && StringUtils.isBlank(deptsment.get(i).getSixDept())
                        && StringUtils.isBlank(deptsment.get(i).getSevenDept())
                        && StringUtils.isBlank(deptsment.get(i).getEightDept())
                        && StringUtils.isBlank(deptsment.get(i).getNineDept())
                        && StringUtils.isBlank(deptsment.get(i).getTenDept())) {

                    List<MDept>list=new ArrayList<MDept>();//属于那条线
                    if(depts.size()>0){
                        int count1=0;
                        for(List<MDept> mDepts:depts){
                            for(MDept mDept:mDepts){
                                String str=String.valueOf(mDept.getLevel());
                                if(str.equals("1")&&mDept.getDeptName().equals(deptsment.get(i).getOneDept())){
                                    count1+=1;
                                }
                                if(str.equals("2")&&mDept.getDeptName().equals(deptsment.get(i).getTwoDept())){
                                    count1+=1;
                                }
                            }
                            if(count1==2){
                                list=mDepts;
                                break;
                            }else{
                                count1=0;
                            }
                        }
                        if(list==null||list.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行当前管理员无此机构");
                            throw new RuntimeException("第" + (i + 1) + "行当前管理员无此机构");
                        }else{
                            int count=0;
                            for(MDept mDept:list){
                                if("3".equals(mDept.getLevel())){
                                    count+=1;
                                }
                            }
                            if(count!=0){
                                tidings.setStatus(Const.ERROR);
                                tidings.setMsg("第" + (i + 1) + "行选择末级机构");
                                throw new RuntimeException("第" + (i + 1) + "行选择末级机构");
                            }else{
                                for(MDept mDept:list){
                                    String str=String.valueOf(mDept.getLevel());
                                    if("2".equals(str)&&deptsment.get(i).getTwoDept().equals(mDept.getDeptName())){
                                        mfeu.setDeptId(mDept.getDeptId());
                                    }
                                }
                                if(mfeu.getDeptId()==null){
                                    tidings.setStatus(Const.ERROR);
                                    tidings.setMsg("第" + (i + 1) + "行末级机构错误");
                                    throw new RuntimeException("第" + (i + 1) + "行末级机构错误");
                                }
                            }
                        }
                    }else{
                        map.put("deptName", deptsment.get(i).getOneDept());
                        map.put("level", "1");
                        map.put("cropId", cropId);
                        List<MDept> mDept2 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept2==null||mDept2.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此一级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此一级机构");
                        }
                        map.put("deptName", deptsment.get(i).getTwoDept());
                        map.put("level", "2");
                        map.put("cropId", cropId);
                        List<MDept> mDept = mdeptService.getDeptByNameAndLevel(map);//依据部门名称和等级查找是否存在此部门
                        if(mDept.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此末级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此末级机构");
                        }
                        MDept mDept5=null;
                        for(MDept mDept1:mDept){
                            if(mDept1.getSuperDeptId().equals(mDept2.get(0).getDeptId())){
                                mDept5=mDept1;
                            }
                        }
                        if(mDept5==null){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行二级机构层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行二级机构层级错误");
                        }
                        List<MDept> mDept1 = mdeptService.getsonDept(mDept5.getDeptId());
                        if (mDept1.size() == 0 || mDept1 == null) {
                            mfeu.setDeptId(mDept5.getDeptId());
                        } else {
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行请填写末级部门");
                            throw new RuntimeException("第" + (i + 1) + "行请填写末级部门");
                        }
                    }
                }else if (StringUtils.isNotBlank(deptsment.get(i).getOneDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getTwoDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getThreeDept())
                        && StringUtils.isBlank(deptsment.get(i).getFourDept())
                        && StringUtils.isBlank(deptsment.get(i).getFiveDept())
                        && StringUtils.isBlank(deptsment.get(i).getSixDept())
                        && StringUtils.isBlank(deptsment.get(i).getSevenDept())
                        && StringUtils.isBlank(deptsment.get(i).getEightDept())
                        && StringUtils.isBlank(deptsment.get(i).getNineDept())
                        && StringUtils.isBlank(deptsment.get(i).getTenDept())) {

                    List<MDept>list=null;//属于那条线
                    if(depts.size()>0){
                        int count1=0;
                        for(List<MDept> mDepts:depts){
                            for(MDept mDept:mDepts){
                                String str=String.valueOf(mDept.getLevel());
                                if(str.equals("1")&&mDept.getDeptName().equals(deptsment.get(i).getOneDept())){
                                    count1+=1;
                                }
                                if(str.equals("2")&&mDept.getDeptName().equals(deptsment.get(i).getTwoDept())){
                                    count1+=1;
                                }
                                if(str.equals("3")&&mDept.getDeptName().equals(deptsment.get(i).getThreeDept())){
                                    count1+=1;
                                }
                            }
                            if(count1==3){
                                list=mDepts;
                                break;
                            }else{
                                count1=0;
                            }
                        }
                        if(list==null ||list.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行部门层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行部门层级错误");
                        }else{
                            int count=0;
                            for(MDept mDept:list){
                                if("4".equals(mDept.getLevel())){
                                    count+=1;
                                }
                            }
                            if(count!=0){
                                tidings.setStatus(Const.ERROR);
                                tidings.setMsg("第" + (i + 1) + "行选择末级机构");
                                throw new RuntimeException("第" + (i + 1) + "行选择末级机构");
                            }else{
                                for(MDept mDept:list){
                                    String str=String.valueOf(mDept.getLevel());
                                    if("3".equals(str)&&deptsment.get(i).getThreeDept().equals(mDept.getDeptName())){
                                        mfeu.setDeptId(mDept.getDeptId());
                                    }
                                }
                                if(mfeu.getDeptId()==null){
                                    tidings.setStatus(Const.ERROR);
                                    tidings.setMsg("第" + (i + 1) + "行末级机构错误");
                                    throw new RuntimeException("第" + (i + 1) + "行末级机构错误");
                                }
                            }
                        }
                    }else{
                        map.put("deptName", deptsment.get(i).getOneDept());
                        map.put("level", "1");
                        map.put("cropId", cropId);
                        List<MDept> mDept2 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept2==null||mDept2.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此一级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此一级机构");
                        }
                        map.put("deptName", deptsment.get(i).getTwoDept());
                        map.put("level", "2");
                        map.put("cropId", cropId);
                        List<MDept> mDept3 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept3==null||mDept3.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此二级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此二级机构");
                        }
                        map.put("deptName", deptsment.get(i).getThreeDept());
                        map.put("level", "3");
                        map.put("cropId", cropId);
                        List<MDept> mDept = mdeptService.getDeptByNameAndLevel(map);//依据部门名称和等级查找是否存在此部门
                        if(mDept.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此末级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此末级机构");
                        }
                        MDept mDept5=null;
                        for(MDept mDept1:mDept3){
                            if(mDept1.getSuperDeptId().equals(mDept2.get(0).getDeptId())){
                                mDept5=mDept1;
                            }
                        }
                        if(mDept5==null){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行二级机构层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行二级机构层级错误");
                        }
                        MDept mDept6=null;
                        for(MDept mDept1:mDept){
                            if(mDept1.getSuperDeptId().equals(mDept5.getDeptId())){
                                mDept6=mDept1;
                            }
                        }
                        if(mDept6==null){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行三级机构层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行三级机构层级错误");
                        }
                        List<MDept> mDept1 = mdeptService.getsonDept(mDept6.getDeptId());
                        if (mDept1.size() == 0 || mDept1 == null) {
                            mfeu.setDeptId(mDept6.getDeptId());
                        } else {
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行请填写末级部门");
                            throw new RuntimeException("第" + (i + 1) + "行请填写末级部门");
                        }
                    }
                } else if (StringUtils.isNotBlank(deptsment.get(i).getOneDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getTwoDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getThreeDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getFourDept())
                        && StringUtils.isBlank(deptsment.get(i).getFiveDept())
                        && StringUtils.isBlank(deptsment.get(i).getSixDept())
                        && StringUtils.isBlank(deptsment.get(i).getSevenDept())
                        && StringUtils.isBlank(deptsment.get(i).getEightDept())
                        && StringUtils.isBlank(deptsment.get(i).getNineDept())
                        && StringUtils.isBlank(deptsment.get(i).getTenDept())) {

                    List<MDept>list=null;//属于那条线
                    if(depts.size()>0){
                        int count1=0;
                        for(List<MDept> mDepts:depts){
                            for(MDept mDept:mDepts){
                                String str=String.valueOf(mDept.getLevel());
                                if(str.equals("1")&&mDept.getDeptName().equals(deptsment.get(i).getOneDept())){
                                    count1+=1;
                                }
                                if(str.equals("2")&&mDept.getDeptName().equals(deptsment.get(i).getTwoDept())){
                                    count1+=1;
                                }
                                if(str.equals("3")&&mDept.getDeptName().equals(deptsment.get(i).getThreeDept())){
                                    count1+=1;
                                }
                                if(str.equals("4")&&mDept.getDeptName().equals(deptsment.get(i).getFourDept())){
                                    count1+=1;
                                }
                            }
                            if(count1==4){
                                list=mDepts;
                                break;
                            }else{
                                count1=0;
                            }
                        }
                        if(list==null ||list.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行部门层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行部门层级错误");
                        }else{
                            int count=0;
                            for(MDept mDept:list){
                                if("5".equals(mDept.getLevel())){
                                    count+=1;
                                }
                            }
                            if(count!=0){
                                tidings.setStatus(Const.ERROR);
                                tidings.setMsg("第" + (i + 1) + "行选择末级机构");
                                throw new RuntimeException("第" + (i + 1) + "行选择末级机构");
                            }else{
                                for(MDept mDept:list){
                                    String str=String.valueOf(mDept.getLevel());
                                    if("4".equals(str)&&deptsment.get(i).getFourDept().equals(mDept.getDeptName())){
                                        mfeu.setDeptId(mDept.getDeptId());
                                    }
                                }
                                if(mfeu.getDeptId()==null){
                                    tidings.setStatus(Const.ERROR);
                                    tidings.setMsg("第" + (i + 1) + "行末级机构错误");
                                    throw new RuntimeException("第" + (i + 1) + "行末级机构错误");
                                }
                            }
                        }
                    }else{

                        map.put("deptName", deptsment.get(i).getOneDept());
                        map.put("level", "1");
                        map.put("cropId", cropId);
                        List<MDept> mDept2 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept2==null||mDept2.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此一级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此一级机构");
                        }
                        map.put("deptName", deptsment.get(i).getTwoDept());
                        map.put("level", "2");
                        map.put("cropId", cropId);
                        List<MDept> mDept3 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept3==null||mDept3.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此二级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此二级机构");
                        }
                        map.put("deptName", deptsment.get(i).getThreeDept());
                        map.put("level", "3");
                        map.put("cropId", cropId);
                        List<MDept> mDept4 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept4==null||mDept4.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此三级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此三级机构");
                        }
                        map.put("deptName", deptsment.get(i).getFourDept());
                        map.put("level", "4");
                        map.put("cropId", cropId);
                        List<MDept> mDept = mdeptService.getDeptByNameAndLevel(map);//依据部门名称和等级查找是否存在此部门
                        if(mDept.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此末级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此末级机构");
                        }
                        MDept mDept5=null;
                        for(MDept mDept1:mDept3){
                            if(mDept1.getSuperDeptId().equals(mDept2.get(0).getDeptId())){
                                mDept5=mDept1;
                            }
                        }
                        if(mDept5==null){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行二级机构层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行二级机构层级错误");
                        }
                        MDept mDept6=null;
                        for(MDept mDept1:mDept4){
                            if(mDept1.getSuperDeptId().equals(mDept5.getDeptId())){
                                mDept6=mDept1;
                            }
                        }
                        MDept mDept7=null;
                        for(MDept mDept1:mDept){
                            if(mDept1.getSuperDeptId().equals(mDept6.getDeptId())){
                                mDept7=mDept1;
                            }
                        }
                        if(mDept7==null){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行三级机构层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行三级机构层级错误");
                        }
                        List<MDept> mDept1 = mdeptService.getsonDept(mDept7.getDeptId());
                        if (mDept1.size() == 0 || mDept1 == null) {
                            mfeu.setDeptId(mDept7.getDeptId());
                        } else {
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行请填写末级部门");
                            throw new RuntimeException("第" + (i + 1) + "行请填写末级部门");
                        }
                    }
                }else if (StringUtils.isNotBlank(deptsment.get(i).getOneDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getTwoDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getThreeDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getFourDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getFiveDept())
                        && StringUtils.isBlank(deptsment.get(i).getSixDept())
                        && StringUtils.isBlank(deptsment.get(i).getSevenDept())
                        && StringUtils.isBlank(deptsment.get(i).getEightDept())
                        && StringUtils.isBlank(deptsment.get(i).getNineDept())
                        && StringUtils.isBlank(deptsment.get(i).getTenDept())) {

                    List<MDept>list=null;//属于那条线
                    if(depts.size()>0){
                        int count1=0;
                        for(List<MDept> mDepts:depts){
                            for(MDept mDept:mDepts){
                                String str=String.valueOf(mDept.getLevel());
                                if(str.equals("1")&&mDept.getDeptName().equals(deptsment.get(i).getOneDept())){
                                    count1+=1;
                                }
                                if(str.equals("2")&&mDept.getDeptName().equals(deptsment.get(i).getTwoDept())){
                                    count1+=1;
                                }
                                if(str.equals("3")&&mDept.getDeptName().equals(deptsment.get(i).getThreeDept())){
                                    count1+=1;
                                }
                                if(str.equals("4")&&mDept.getDeptName().equals(deptsment.get(i).getFourDept())){
                                    count1+=1;
                                }
                                if(str.equals("5")&&mDept.getDeptName().equals(deptsment.get(i).getFiveDept())){
                                    count1+=1;
                                }
                            }
                            if(count1==5){
                                list=mDepts;
                                break;
                            }else{
                                count1=0;
                            }
                        }
                        if(list==null ||list.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行部门层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行部门层级错误");
                        }else{
                            int count=0;
                            for(MDept mDept:list){
                                if("6".equals(mDept.getLevel())){
                                    count+=1;
                                }
                            }
                            if(count!=0){
                                tidings.setStatus(Const.ERROR);
                                tidings.setMsg("第" + (i + 1) + "行选择末级机构");
                                throw new RuntimeException("第" + (i + 1) + "行选择末级机构");
                            }else{
                                for(MDept mDept:list){
                                    String str=String.valueOf(mDept.getLevel());
                                    if("5".equals(str)&&deptsment.get(i).getFiveDept().equals(mDept.getDeptName())){
                                        mfeu.setDeptId(mDept.getDeptId());
                                    }
                                }
                                if(mfeu.getDeptId()==null){
                                    tidings.setStatus(Const.ERROR);
                                    tidings.setMsg("第" + (i + 1) + "行末级机构错误");
                                    throw new RuntimeException("第" + (i + 1) + "行末级机构错误");
                                }
                            }
                        }
                    }else{

                        map.put("deptName", deptsment.get(i).getOneDept());
                        map.put("level", "1");
                        map.put("cropId", cropId);
                        List<MDept> mDept2 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept2==null||mDept2.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此一级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此末级机构");
                        }
                        map.put("deptName", deptsment.get(i).getTwoDept());
                        map.put("level", "2");
                        map.put("cropId", cropId);
                        List<MDept> mDept3 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept3==null||mDept3.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此二级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此二级机构");
                        }
                        map.put("deptName", deptsment.get(i).getThreeDept());
                        map.put("level", "3");
                        map.put("cropId", cropId);
                        List<MDept> mDept4 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept4==null||mDept4.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此三级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此三级机构");
                        }
                        map.put("deptName", deptsment.get(i).getFourDept());
                        map.put("level", "4");
                        map.put("cropId", cropId);
                        List<MDept> mDept7 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept7==null||mDept7.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此四级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此四级机构");
                        }
                        map.put("deptName", deptsment.get(i).getFiveDept());
                        map.put("level", "5");
                        map.put("cropId", cropId);
                        List<MDept> mDept = mdeptService.getDeptByNameAndLevel(map);//依据部门名称和等级查找是否存在此部门
                        if(mDept.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此末级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此末级机构");
                        }
                        MDept mDept5=null;
                        for(MDept mDept1:mDept3){
                            if(mDept1.getSuperDeptId().equals(mDept2.get(0).getDeptId())){
                                mDept5=mDept1;
                            }
                        }
                        if(mDept5==null){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行二级机构层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行二级机构层级错误");
                        }
                        MDept mDept6=null;
                        for(MDept mDept1:mDept4){
                            if(mDept1.getSuperDeptId().equals(mDept5.getDeptId())){
                                mDept6=mDept1;
                            }
                        }
                        MDept mDept11=null;
                        for(MDept mDept1:mDept7){
                            if(mDept1.getSuperDeptId().equals(mDept6.getDeptId())){
                                mDept11=mDept1;
                            }
                        }
                        if(mDept11==null){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行三级机构层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行三级机构层级错误");
                        }
                        MDept mDept8=null;
                        for(MDept mDept1:mDept){
                            if(mDept1.getSuperDeptId().equals(mDept11.getDeptId())){
                                mDept8=mDept1;
                            }
                        }
                        if(mDept8==null){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行四级机构层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行四级机构层级错误");
                        }
                        List<MDept> mDept1 = mdeptService.getsonDept(mDept8.getDeptId());
                        if (mDept1.size() == 0 || mDept1 == null) {
                            mfeu.setDeptId(mDept8.getDeptId());
                        } else {
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行请填写末级部门");
                            throw new RuntimeException("第" + (i + 1) + "行请填写末级部门");
                        }
                    }
                }else if (StringUtils.isNotBlank(deptsment.get(i).getOneDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getTwoDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getThreeDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getFourDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getFiveDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getSixDept())
                        && StringUtils.isBlank(deptsment.get(i).getSevenDept())
                        && StringUtils.isBlank(deptsment.get(i).getEightDept())
                        && StringUtils.isBlank(deptsment.get(i).getNineDept())
                        && StringUtils.isBlank(deptsment.get(i).getTenDept())) {

                    List<MDept>list=null;//属于那条线
                    if(depts.size()>0){
                        int count1=0;
                        for(List<MDept> mDepts:depts){
                            for(MDept mDept:mDepts){
                                String str=String.valueOf(mDept.getLevel());
                                if(str.equals("1")&&mDept.getDeptName().equals(deptsment.get(i).getOneDept())){
                                    count1+=1;
                                }
                                if(str.equals("2")&&mDept.getDeptName().equals(deptsment.get(i).getTwoDept())){
                                    count1+=1;
                                }
                                if(str.equals("3")&&mDept.getDeptName().equals(deptsment.get(i).getThreeDept())){
                                    count1+=1;
                                }
                                if(str.equals("4")&&mDept.getDeptName().equals(deptsment.get(i).getFourDept())){
                                    count1+=1;
                                }
                                if(str.equals("5")&&mDept.getDeptName().equals(deptsment.get(i).getFiveDept())){
                                    count1+=1;
                                }
                                if(str.equals("6")&&mDept.getDeptName().equals(deptsment.get(i).getSixDept())){
                                    count1+=1;
                                }

                            }
                            if(count1==6){
                                list=mDepts;
                                break;
                            }else{
                                count1=0;
                            }
                        }
                        if(list==null ||list.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行部门层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行部门层级错误");
                        }else{
                            int count=0;
                            for(MDept mDept:list){
                                if("7".equals(mDept.getLevel())){
                                    count+=1;
                                }
                            }
                            if(count!=0){
                                tidings.setStatus(Const.ERROR);
                                tidings.setMsg("第" + (i + 1) + "行选择末级机构");
                                throw new RuntimeException("第" + (i + 1) + "行选择末级机构");
                            }else{
                                for(MDept mDept:list){
                                    String str=String.valueOf(mDept.getLevel());
                                    if("6".equals(str)&&deptsment.get(i).getSixDept().equals(mDept.getDeptName())){
                                        mfeu.setDeptId(mDept.getDeptId());
                                    }
                                }
                                if(mfeu.getDeptId()==null){
                                    tidings.setStatus(Const.ERROR);
                                    tidings.setMsg("第" + (i + 1) + "行末级机构错误");
                                    throw new RuntimeException("第" + (i + 1) + "行末级机构错误");
                                }
                            }
                        }
                    }else{

                        map.put("deptName", deptsment.get(i).getOneDept());
                        map.put("level", "1");
                        map.put("cropId", cropId);
                        List<MDept> mDept2 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept2==null||mDept2.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此一级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此一级机构");
                        }
                        map.put("deptName", deptsment.get(i).getTwoDept());
                        map.put("level", "2");
                        map.put("cropId", cropId);
                        List<MDept> mDept3 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept3==null||mDept3.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此二级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此二级机构");
                        }
                        map.put("deptName", deptsment.get(i).getThreeDept());
                        map.put("level", "3");
                        map.put("cropId", cropId);
                        List<MDept> mDept4 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept4==null||mDept4.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此三级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此三级机构");
                        }
                        map.put("deptName", deptsment.get(i).getFourDept());
                        map.put("level", "4");
                        map.put("cropId", cropId);
                        List<MDept> mDept7 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept7==null||mDept7.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此四级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此四级机构");
                        }
                        map.put("deptName", deptsment.get(i).getFiveDept());
                        map.put("level", "5");
                        map.put("cropId", cropId);
                        List<MDept> mDept17 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept17==null||mDept17.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此五级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此五级机构");
                        }
                        map.put("deptName", deptsment.get(i).getSixDept());
                        map.put("level", "6");
                        map.put("cropId", cropId);
                        List<MDept> mDept = mdeptService.getDeptByNameAndLevel(map);//依据部门名称和等级查找是否存在此部门
                        if(mDept.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此末级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此末级机构");
                        }
                        MDept mDept5=null;
                        for(MDept mDept1:mDept3){
                            if(mDept1.getSuperDeptId().equals(mDept2.get(0).getDeptId())){
                                mDept5=mDept1;
                            }
                        }
                        if(mDept5==null){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行二级机构层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行二级机构层级错误");
                        }
                        MDept mDept6=null;
                        for(MDept mDept1:mDept4){
                            if(mDept1.getSuperDeptId().equals(mDept5.getDeptId())){
                                mDept6=mDept1;
                            }
                        }
                        MDept mDept11=null;
                        for(MDept mDept1:mDept7){
                            if(mDept1.getSuperDeptId().equals(mDept6.getDeptId())){
                                mDept11=mDept1;
                            }
                        }
                        if(mDept11==null){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行三级机构层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行三级机构层级错误");
                        }
                        MDept mDept12=null;
                        for(MDept mDept1:mDept17){
                            if(mDept1.getSuperDeptId().equals(mDept11.getDeptId())){
                                mDept12=mDept1;
                            }
                        }
                        if(mDept12==null){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行四级机构层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行四级机构层级错误");
                        }

                        MDept mDept8=null;
                        for(MDept mDept1:mDept){
                            if(mDept1.getSuperDeptId().equals(mDept12.getDeptId())){
                                mDept8=mDept1;
                            }
                        }
                        if(mDept8==null){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行五级机构层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行五级机构层级错误");
                        }
                        List<MDept> mDept1 = mdeptService.getsonDept(mDept8.getDeptId());
                        if (mDept1.size() == 0 || mDept1 == null) {
                            mfeu.setDeptId(mDept8.getDeptId());
                        } else {
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行请填写末级部门");
                            throw new RuntimeException("第" + (i + 1) + "行请填写末级部门");
                        }
                    }
                }else if (StringUtils.isNotBlank(deptsment.get(i).getOneDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getTwoDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getThreeDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getFourDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getFiveDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getSixDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getSevenDept())
                        && StringUtils.isBlank(deptsment.get(i).getEightDept())
                        && StringUtils.isBlank(deptsment.get(i).getNineDept())
                        && StringUtils.isBlank(deptsment.get(i).getTenDept())) {

                    List<MDept>list=null;//属于那条线
                    if(depts.size()>0){
                        int count1=0;
                        for(List<MDept> mDepts:depts){
                            for(MDept mDept:mDepts){
                                String str=String.valueOf(mDept.getLevel());
                                if(str.equals("1")&&mDept.getDeptName().equals(deptsment.get(i).getOneDept())){
                                    count1+=1;
                                }
                                if(str.equals("2")&&mDept.getDeptName().equals(deptsment.get(i).getTwoDept())){
                                    count1+=1;
                                }
                                if(str.equals("3")&&mDept.getDeptName().equals(deptsment.get(i).getThreeDept())){
                                    count1+=1;
                                }
                                if(str.equals("4")&&mDept.getDeptName().equals(deptsment.get(i).getFourDept())){
                                    count1+=1;
                                }
                                if(str.equals("5")&&mDept.getDeptName().equals(deptsment.get(i).getFiveDept())){
                                    count1+=1;
                                }
                                if(str.equals("6")&&mDept.getDeptName().equals(deptsment.get(i).getSixDept())){
                                    count1+=1;
                                }
                                if(str.equals("7")&&mDept.getDeptName().equals(deptsment.get(i).getSevenDept())){
                                    count1+=1;
                                }
                            }/////////
                            if(count1==7){
                                list=mDepts;
                                break;
                            }else{
                                count1=0;
                            }
                        }
                        if(list==null ||list.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行部门层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行部门层级错误");
                        }else{
                            int count=0;
                            for(MDept mDept:list){
                                if("8".equals(mDept.getLevel())){
                                    count+=1;
                                }
                            }
                            if(count!=0){
                                tidings.setStatus(Const.ERROR);
                                tidings.setMsg("第" + (i + 1) + "行选择末级机构");
                                throw new RuntimeException("第" + (i + 1) + "行选择末级机构");
                            }else{
                                for(MDept mDept:list){
                                    String str=String.valueOf(mDept.getLevel());
                                    if("7".equals(str)&&deptsment.get(i).getSevenDept().equals(mDept.getDeptName())){
                                        mfeu.setDeptId(mDept.getDeptId());
                                    }
                                }
                                if(mfeu.getDeptId()==null){
                                    tidings.setStatus(Const.ERROR);
                                    tidings.setMsg("第" + (i + 1) + "行末级机构错误");
                                    throw new RuntimeException("第" + (i + 1) + "行末级机构错误");
                                }
                            }
                        }
                    }else{
                        map.put("deptName", deptsment.get(i).getOneDept());
                        map.put("level", "1");
                        map.put("cropId", cropId);
                        List<MDept> mDept2 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept2==null||mDept2.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此一级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此一级机构");
                        }
                        map.put("deptName", deptsment.get(i).getTwoDept());
                        map.put("level", "2");
                        map.put("cropId", cropId);
                        List<MDept> mDept3 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept3==null||mDept3.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此二级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此二级机构");
                        }
                        map.put("deptName", deptsment.get(i).getThreeDept());
                        map.put("level", "3");
                        map.put("cropId", cropId);
                        List<MDept> mDept4 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept4==null||mDept4.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此三级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此三级机构");
                        }
                        map.put("deptName", deptsment.get(i).getFourDept());
                        map.put("level", "4");
                        map.put("cropId", cropId);
                        List<MDept> mDept7 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept7==null||mDept7.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此四级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此四级机构");
                        }
                        map.put("deptName", deptsment.get(i).getFiveDept());
                        map.put("level", "5");
                        map.put("cropId", cropId);
                        List<MDept> mDept17 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept17==null||mDept17.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此五级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此五级机构");
                        }
                        map.put("deptName", deptsment.get(i).getSixDept());
                        map.put("level", "6");
                        map.put("cropId", cropId);
                        List<MDept> mDept18 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept18==null||mDept18.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此六级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此六级机构");
                        }
                        map.put("deptName", deptsment.get(i).getSevenDept());
                        map.put("level", "7");
                        map.put("cropId", cropId);
                        List<MDept> mDept = mdeptService.getDeptByNameAndLevel(map);//依据部门名称和等级查找是否存在此部门
                        if(mDept.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此末级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此末级机构");
                        }
                        MDept mDept5=null;
                        for(MDept mDept1:mDept3){
                            if(mDept1.getSuperDeptId().equals(mDept2.get(0).getDeptId())){
                                mDept5=mDept1;
                            }
                        }
                        if(mDept5==null){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行二级机构层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行二级机构层级错误");
                        }
                        MDept mDept6=null;
                        for(MDept mDept1:mDept4){
                            if(mDept1.getSuperDeptId().equals(mDept5.getDeptId())){
                                mDept6=mDept1;
                            }
                        }
                        MDept mDept11=null;
                        for(MDept mDept1:mDept7){
                            if(mDept1.getSuperDeptId().equals(mDept6.getDeptId())){
                                mDept11=mDept1;
                            }
                        }
                        if(mDept11==null){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行三级机构层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行三级机构层级错误");
                        }
                        MDept mDept12=null;
                        for(MDept mDept1:mDept17){
                            if(mDept1.getSuperDeptId().equals(mDept11.getDeptId())){
                                mDept12=mDept1;
                            }
                        }
                        if(mDept12==null){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行四级机构层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行四级机构层级错误");
                        }
                        MDept mDept13=null;
                        for(MDept mDept1:mDept18){
                            if(mDept1.getSuperDeptId().equals(mDept12.getDeptId())){
                                mDept13=mDept1;
                            }
                        }
                        if(mDept13==null){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行五级机构层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行五级机构层级错误");
                        }
                        MDept mDept8=null;
                        for(MDept mDept1:mDept){
                            if(mDept1.getSuperDeptId().equals(mDept13.getDeptId())){
                                mDept8=mDept1;
                            }
                        }
                        if(mDept8==null){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行六级机构层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行六级机构层级错误");
                        }
                        List<MDept> mDept1 = mdeptService.getsonDept(mDept8.getDeptId());
                        if (mDept1.size() == 0 || mDept1 == null) {
                            mfeu.setDeptId(mDept8.getDeptId());
                        } else {
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行请填写末级部门");
                            throw new RuntimeException("第" + (i + 1) + "行请填写末级部门");
                        }
                    }
                } else if (StringUtils.isNotBlank(deptsment.get(i).getOneDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getTwoDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getThreeDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getFourDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getFiveDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getSixDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getSevenDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getEightDept())
                        && StringUtils.isBlank(deptsment.get(i).getNineDept())
                        && StringUtils.isBlank(deptsment.get(i).getTenDept())) {

                    List<MDept>list=null;//属于那条线
                    if(depts.size()>0){
                        int count1=0;
                        for(List<MDept> mDepts:depts){
                            for(MDept mDept:mDepts){
                                String str=String.valueOf(mDept.getLevel());
                                if(str.equals("1")&&mDept.getDeptName().equals(deptsment.get(i).getOneDept())){
                                    count1+=1;
                                }
                                if(str.equals("2")&&mDept.getDeptName().equals(deptsment.get(i).getTwoDept())){
                                    count1+=1;
                                }
                                if(str.equals("3")&&mDept.getDeptName().equals(deptsment.get(i).getThreeDept())){
                                    count1+=1;
                                }
                                if(str.equals("4")&&mDept.getDeptName().equals(deptsment.get(i).getFourDept())){
                                    count1+=1;
                                }
                                if(str.equals("5")&&mDept.getDeptName().equals(deptsment.get(i).getFiveDept())){
                                    count1+=1;
                                }
                                if(str.equals("6")&&mDept.getDeptName().equals(deptsment.get(i).getSixDept())){
                                    count1+=1;
                                }
                                if(str.equals("7")&&mDept.getDeptName().equals(deptsment.get(i).getSevenDept())){
                                    count1+=1;
                                }
                                if(str.equals("8")&&mDept.getDeptName().equals(deptsment.get(i).getEightDept())){
                                    count1+=1;
                                }
                            }
                            if(count1==8){
                                list=mDepts;
                                break;
                            }else{
                                count1=0;
                            }
                        }
                        if(list==null ||list.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行部门层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行部门层级错误");
                        }else{
                            int count=0;
                            for(MDept mDept:list){
                                if("9".equals(mDept.getLevel())){
                                    count+=1;
                                }
                            }
                            if(count!=0){
                                tidings.setStatus(Const.ERROR);
                                tidings.setMsg("第" + (i + 1) + "行选择末级机构");
                                throw new RuntimeException("第" + (i + 1) + "行选择末级机构");
                            }else{
                                for(MDept mDept:list){
                                    String str=String.valueOf(mDept.getLevel());
                                    if("8".equals(str)&&deptsment.get(i).getEightDept().equals(mDept.getDeptName())){
                                        mfeu.setDeptId(mDept.getDeptId());
                                    }
                                }
                                if(mfeu.getDeptId()==null){
                                    tidings.setStatus(Const.ERROR);
                                    tidings.setMsg("第" + (i + 1) + "行末级机构错误");
                                    throw new RuntimeException("第" + (i + 1) + "行末级机构错误");
                                }
                            }
                        }
                    }else{
                        map.put("deptName", deptsment.get(i).getOneDept());
                        map.put("level", "1");
                        map.put("cropId", cropId);
                        List<MDept> mDept2 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept2==null||mDept2.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此一级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此一级机构");
                        }
                        map.put("deptName", deptsment.get(i).getTwoDept());
                        map.put("level", "2");
                        map.put("cropId", cropId);
                        List<MDept> mDept3 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept3==null||mDept3.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此二级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此二级机构");
                        }
                        map.put("deptName", deptsment.get(i).getThreeDept());
                        map.put("level", "3");
                        map.put("cropId", cropId);
                        List<MDept> mDept4 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept4==null||mDept4.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此三级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此三级机构");
                        }
                        map.put("deptName", deptsment.get(i).getFourDept());
                        map.put("level", "4");
                        map.put("cropId", cropId);
                        List<MDept> mDept7 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept7==null||mDept7.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此四级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此四级机构");
                        }
                        map.put("deptName", deptsment.get(i).getFiveDept());
                        map.put("level", "5");
                        map.put("cropId", cropId);
                        List<MDept> mDept17 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept17==null||mDept17.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此五级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此五级机构");
                        }
                        map.put("deptName", deptsment.get(i).getSixDept());
                        map.put("level", "6");
                        map.put("cropId", cropId);
                        List<MDept> mDept18 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept18==null||mDept18.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此六级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此六级机构");
                        }
                        map.put("deptName", deptsment.get(i).getSevenDept());
                        map.put("level", "7");
                        map.put("cropId", cropId);
                        List<MDept> mDept19 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept19==null||mDept19.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此七级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此七级机构");
                        }
                        map.put("deptName", deptsment.get(i).getEightDept());
                        map.put("level", "8");
                        map.put("cropId", cropId);
                        List<MDept> mDept = mdeptService.getDeptByNameAndLevel(map);//依据部门名称和等级查找是否存在此部门
                        if(mDept.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此末级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此末级机构");
                        }
                        MDept mDept5=null;
                        for(MDept mDept1:mDept3){
                            if(mDept1.getSuperDeptId().equals(mDept2.get(0).getDeptId())){
                                mDept5=mDept1;
                            }
                        }
                        if(mDept5==null){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行二级机构层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行二级机构层级错误");
                        }
                        MDept mDept6=null;
                        for(MDept mDept1:mDept4){
                            if(mDept1.getSuperDeptId().equals(mDept5.getDeptId())){
                                mDept6=mDept1;
                            }
                        }
                        MDept mDept11=null;
                        for(MDept mDept1:mDept7){
                            if(mDept1.getSuperDeptId().equals(mDept6.getDeptId())){
                                mDept11=mDept1;
                            }
                        }
                        if(mDept11==null){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行三级机构层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行三级机构层级错误");
                        }
                        MDept mDept12=null;
                        for(MDept mDept1:mDept17){
                            if(mDept1.getSuperDeptId().equals(mDept11.getDeptId())){
                                mDept12=mDept1;
                            }
                        }
                        if(mDept12==null){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行四级机构层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行四级机构层级错误");
                        }
                        MDept mDept13=null;
                        for(MDept mDept1:mDept18){
                            if(mDept1.getSuperDeptId().equals(mDept12.getDeptId())){
                                mDept13=mDept1;
                            }
                        }
                        if(mDept13==null){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行五级机构层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行五级机构层级错误");
                        }
                        MDept mDept14=null;
                        for(MDept mDept1:mDept19){
                            if(mDept1.getSuperDeptId().equals(mDept13.getDeptId())){
                                mDept14=mDept1;
                            }
                        }
                        if(mDept14==null){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行六级机构层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行六级机构层级错误");
                        }
                        MDept mDept8=null;
                        for(MDept mDept1:mDept){
                            if(mDept1.getSuperDeptId().equals(mDept14.getDeptId())){
                                mDept8=mDept1;
                            }
                        }
                        if(mDept8==null){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行七级机构层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行七级机构层级错误");
                        }
                        List<MDept> mDept1 = mdeptService.getsonDept(mDept8.getDeptId());
                        if (mDept1.size() == 0 || mDept1 == null) {
                            mfeu.setDeptId(mDept8.getDeptId());
                        } else {
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行请填写末级部门");
                            throw new RuntimeException("第" + (i + 1) + "行请填写末级部门");
                        }
                    }
                }else if (StringUtils.isNotBlank(deptsment.get(i).getOneDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getTwoDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getThreeDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getFourDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getFiveDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getSixDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getSevenDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getEightDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getNineDept())
                        && StringUtils.isBlank(deptsment.get(i).getTenDept())) {

                    List<MDept>list=null;//属于那条线
                    if(depts.size()>0){
                        int count1=0;
                        for(List<MDept> mDepts:depts){
                            for(MDept mDept:mDepts){
                                String str=String.valueOf(mDept.getLevel());
                                if(str.equals("1")&&mDept.getDeptName().equals(deptsment.get(i).getOneDept())){
                                    count1+=1;
                                }
                                if(str.equals("2")&&mDept.getDeptName().equals(deptsment.get(i).getTwoDept())){
                                    count1+=1;
                                }
                                if(str.equals("3")&&mDept.getDeptName().equals(deptsment.get(i).getThreeDept())){
                                    count1+=1;
                                }
                                if(str.equals("4")&&mDept.getDeptName().equals(deptsment.get(i).getFourDept())){
                                    count1+=1;
                                }
                                if(str.equals("5")&&mDept.getDeptName().equals(deptsment.get(i).getFiveDept())){
                                    count1+=1;
                                }
                                if(str.equals("6")&&mDept.getDeptName().equals(deptsment.get(i).getSixDept())){
                                    count1+=1;
                                }
                                if(str.equals("7")&&mDept.getDeptName().equals(deptsment.get(i).getSevenDept())){
                                    count1+=1;
                                }
                                if(str.equals("8")&&mDept.getDeptName().equals(deptsment.get(i).getEightDept())){
                                    count1+=1;
                                }
                                if(str.equals("9")&&mDept.getDeptName().equals(deptsment.get(i).getNineDept())){
                                    count1+=1;
                                }
                            }
                            if(count1==9){
                                list=mDepts;
                                break;
                            }else{
                                count1=0;
                            }
                        }
                        if(list==null ||list.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行部门层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行部门层级错误");
                        }else{
                            int count=0;
                            for(MDept mDept:list){
                                if("10".equals(mDept.getLevel())){
                                    count+=1;
                                }
                            }
                            if(count!=0){
                                tidings.setStatus(Const.ERROR);
                                tidings.setMsg("第" + (i + 1) + "行选择末级机构");
                                throw new RuntimeException("第" + (i + 1) + "行选择末级机构");
                            }else{
                                for(MDept mDept:list){
                                    String str=String.valueOf(mDept.getLevel());
                                    if("9".equals(str)&&deptsment.get(i).getNineDept().equals(mDept.getDeptName())){
                                        mfeu.setDeptId(mDept.getDeptId());
                                    }
                                }
                                if(mfeu.getDeptId()==null){
                                    tidings.setStatus(Const.ERROR);
                                    tidings.setMsg("第" + (i + 1) + "行末级机构错误");
                                    throw new RuntimeException("第" + (i + 1) + "行末级机构错误");
                                }
                            }
                        }
                    }else{
                        map.put("deptName", deptsment.get(i).getOneDept());
                        map.put("level", "1");
                        map.put("cropId", cropId);
                        List<MDept> mDept2 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept2==null||mDept2.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此一级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此一级机构");
                        }
                        map.put("deptName", deptsment.get(i).getTwoDept());
                        map.put("level", "2");
                        map.put("cropId", cropId);
                        List<MDept> mDept3 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept3==null||mDept3.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此二级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此二级机构");
                        }
                        map.put("deptName", deptsment.get(i).getThreeDept());
                        map.put("level", "3");
                        map.put("cropId", cropId);
                        List<MDept> mDept4 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept4==null||mDept4.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此三级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此三级机构");
                        }
                        map.put("deptName", deptsment.get(i).getFourDept());
                        map.put("level", "4");
                        map.put("cropId", cropId);
                        List<MDept> mDept7 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept7==null||mDept7.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此四级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此四级机构");
                        }
                        map.put("deptName", deptsment.get(i).getFiveDept());
                        map.put("level", "5");
                        map.put("cropId", cropId);
                        List<MDept> mDept17 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept17==null||mDept17.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此五级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此五级机构");
                        }
                        map.put("deptName", deptsment.get(i).getSixDept());
                        map.put("level", "6");
                        map.put("cropId", cropId);
                        List<MDept> mDept18 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept18==null||mDept18.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此六级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此六级机构");
                        }
                        map.put("deptName", deptsment.get(i).getSevenDept());
                        map.put("level", "7");
                        map.put("cropId", cropId);
                        List<MDept> mDept19 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept19==null||mDept19.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此七级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此七级机构");
                        }

                        map.put("deptName", deptsment.get(i).getEightDept());
                        map.put("level", "8");
                        map.put("cropId", cropId);
                        List<MDept> mDept20 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept20==null||mDept20.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此八级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此八级机构");
                        }
                        map.put("deptName", deptsment.get(i).getNineDept());
                        map.put("level", "9");
                        map.put("cropId", cropId);
                        List<MDept> mDept = mdeptService.getDeptByNameAndLevel(map);//依据部门名称和等级查找是否存在此部门
                        if(mDept.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此末级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此末级机构");
                        }
                        MDept mDept5=null;
                        for(MDept mDept1:mDept3){
                            if(mDept1.getSuperDeptId().equals(mDept2.get(0).getDeptId())){
                                mDept5=mDept1;
                            }
                        }
                        if(mDept5==null){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行二级机构层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行二级机构层级错误");
                        }
                        MDept mDept6=null;
                        for(MDept mDept1:mDept4){
                            if(mDept1.getSuperDeptId().equals(mDept5.getDeptId())){
                                mDept6=mDept1;
                            }
                        }
                        MDept mDept11=null;
                        for(MDept mDept1:mDept7){
                            if(mDept1.getSuperDeptId().equals(mDept6.getDeptId())){
                                mDept11=mDept1;
                            }
                        }
                        if(mDept11==null){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行三级机构层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行三级机构层级错误");
                        }
                        MDept mDept12=null;
                        for(MDept mDept1:mDept17){
                            if(mDept1.getSuperDeptId().equals(mDept11.getDeptId())){
                                mDept12=mDept1;
                            }
                        }
                        if(mDept12==null){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行四级机构层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行四级机构层级错误");
                        }
                        MDept mDept13=null;
                        for(MDept mDept1:mDept18){
                            if(mDept1.getSuperDeptId().equals(mDept12.getDeptId())){
                                mDept13=mDept1;
                            }
                        }
                        if(mDept13==null){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行五级机构层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行五级机构层级错误");
                        }
                        MDept mDept14=null;
                        for(MDept mDept1:mDept19){
                            if(mDept1.getSuperDeptId().equals(mDept13.getDeptId())){
                                mDept14=mDept1;
                            }
                        }
                        if(mDept14==null){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行六级机构层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行六级机构层级错误");
                        }
                        MDept mDept15=null;
                        for(MDept mDept1:mDept20){
                            if(mDept1.getSuperDeptId().equals(mDept14.getDeptId())){
                                mDept15=mDept1;
                            }
                        }
                        if(mDept15==null){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行七级机构层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行七级机构层级错误");
                        }
                        MDept mDept8=null;
                        for(MDept mDept1:mDept){
                            if(mDept1.getSuperDeptId().equals(mDept15.getDeptId())){
                                mDept8=mDept1;
                            }
                        }
                        if(mDept8==null){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行八级机构层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行八级机构层级错误");
                        }
                        List<MDept> mDept1 = mdeptService.getsonDept(mDept8.getDeptId());
                        if (mDept1.size() == 0 || mDept1 == null) {
                            mfeu.setDeptId(mDept8.getDeptId());
                        } else {
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行请填写末级部门");
                            throw new RuntimeException("第" + (i + 1) + "行请填写末级部门");
                        }
                    }
                }else if (StringUtils.isNotBlank(deptsment.get(i).getOneDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getTwoDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getThreeDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getFourDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getFiveDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getSixDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getSevenDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getEightDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getNineDept())
                        && StringUtils.isNotBlank(deptsment.get(i).getTenDept())) {
                    List<MDept>list=null;//属于那条线
                    if(depts.size()>0){
                        int count1=0;
                        for(List<MDept> mDepts:depts){
                            for(MDept mDept:mDepts){
                                String str=String.valueOf(mDept.getLevel());
                                if(str.equals("1")&&mDept.getDeptName().equals(deptsment.get(i).getOneDept())){
                                    count1+=1;
                                }
                                if(str.equals("2")&&mDept.getDeptName().equals(deptsment.get(i).getTwoDept())){
                                    count1+=1;
                                }
                                if(str.equals("3")&&mDept.getDeptName().equals(deptsment.get(i).getThreeDept())){
                                    count1+=1;
                                }
                                if(str.equals("4")&&mDept.getDeptName().equals(deptsment.get(i).getFourDept())){
                                    count1+=1;
                                }
                                if(str.equals("5")&&mDept.getDeptName().equals(deptsment.get(i).getFiveDept())){
                                    count1+=1;
                                }
                                if(str.equals("6")&&mDept.getDeptName().equals(deptsment.get(i).getSixDept())){
                                    count1+=1;
                                }
                                if(str.equals("7")&&mDept.getDeptName().equals(deptsment.get(i).getSevenDept())){
                                    count1+=1;
                                }
                                if(str.equals("8")&&mDept.getDeptName().equals(deptsment.get(i).getEightDept())){
                                    count1+=1;
                                }
                                if(str.equals("9")&&mDept.getDeptName().equals(deptsment.get(i).getNineDept())){
                                    count1+=1;
                                }
                                if(str.equals("10")&&mDept.getDeptName().equals(deptsment.get(i).getTenDept())){
                                    count1+=1;
                                }
                            }
                            if(count1==10){
                                list=mDepts;
                                break;
                            }else{
                                count1=0;
                            }
                        }
                        if(list==null ||list.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行部门层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行部门层级错误");
                        }else{
                            for(MDept mDept:list){
                                String str=String.valueOf(mDept.getLevel());
                                if("10".equals(str)&&deptsment.get(i).getTenDept().equals(mDept.getDeptName())){
                                    mfeu.setDeptId(mDept.getDeptId());
                                }
                                if(mfeu.getDeptId()==null){
                                    tidings.setStatus(Const.ERROR);
                                    tidings.setMsg("第" + (i + 1) + "行末级机构错误");
                                    throw new RuntimeException("第" + (i + 1) + "行末级机构错误");
                                }
                            }
                        }
                    }else{
                        map.put("deptName", deptsment.get(i).getOneDept());
                        map.put("level", "1");
                        map.put("cropId", cropId);
                        List<MDept> mDept2 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept2==null||mDept2.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此一级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此一级机构");
                        }
                        map.put("deptName", deptsment.get(i).getTwoDept());
                        map.put("level", "2");
                        map.put("cropId", cropId);
                        List<MDept> mDept3 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept3==null||mDept3.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此二级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此二级机构");
                        }
                        map.put("deptName", deptsment.get(i).getThreeDept());
                        map.put("level", "3");
                        map.put("cropId", cropId);
                        List<MDept> mDept4 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept4==null||mDept4.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此三级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此三级机构");
                        }
                        map.put("deptName", deptsment.get(i).getFourDept());
                        map.put("level", "4");
                        map.put("cropId", cropId);
                        List<MDept> mDept7 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept7==null||mDept7.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此四级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此四级机构");
                        }
                        map.put("deptName", deptsment.get(i).getFiveDept());
                        map.put("level", "5");
                        map.put("cropId", cropId);
                        List<MDept> mDept17 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept17==null||mDept17.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此五级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此五级机构");
                        }
                        map.put("deptName", deptsment.get(i).getSixDept());
                        map.put("level", "6");
                        map.put("cropId", cropId);
                        List<MDept> mDept18 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept18==null||mDept18.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此六级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此六级机构");
                        }
                        map.put("deptName", deptsment.get(i).getSevenDept());
                        map.put("level", "7");
                        map.put("cropId", cropId);
                        List<MDept> mDept19 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept19==null||mDept19.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此七级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此七级机构");
                        }
                        map.put("deptName", deptsment.get(i).getEightDept());
                        map.put("level", "8");
                        map.put("cropId", cropId);
                        List<MDept> mDept20 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept20==null||mDept20.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此八级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此八级机构");
                        }
                        map.put("deptName", deptsment.get(i).getNineDept());
                        map.put("level", "9");
                        map.put("cropId", cropId);
                        List<MDept> mDept21 = mdeptService.getDeptByNameAndLevel(map);
                        if(mDept21==null||mDept21.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此九级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此九级机构");
                        }
                        map.put("deptName", deptsment.get(i).getTenDept());
                        map.put("level", "10");
                        map.put("cropId", cropId);
                        List<MDept> mDept = mdeptService.getDeptByNameAndLevel(map);//依据部门名称和等级查找是否存在此部门
                        if(mDept.size()==0){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行无此末级机构");
                            throw new RuntimeException("第" + (i + 1) + "行无此末级机构");
                        }
                        MDept mDept5=null;
                        for(MDept mDept1:mDept3){
                            if(mDept1.getSuperDeptId().equals(mDept2.get(0).getDeptId())){
                                mDept5=mDept1;
                            }
                        }
                        if(mDept5==null){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行二级机构层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行二级机构层级错误");
                        }
                        MDept mDept6=null;
                        for(MDept mDept1:mDept4){
                            if(mDept1.getSuperDeptId().equals(mDept5.getDeptId())){
                                mDept6=mDept1;
                            }
                        }
                        MDept mDept11=null;
                        for(MDept mDept1:mDept7){
                            if(mDept1.getSuperDeptId().equals(mDept6.getDeptId())){
                                mDept11=mDept1;
                            }
                        }
                        if(mDept11==null){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行三级机构层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行三级机构层级错误");
                        }
                        MDept mDept12=null;
                        for(MDept mDept1:mDept17){
                            if(mDept1.getSuperDeptId().equals(mDept11.getDeptId())){
                                mDept12=mDept1;
                            }
                        }
                        if(mDept12==null){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行四级机构层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行四级机构层级错误");
                        }
                        MDept mDept13=null;
                        for(MDept mDept1:mDept18){
                            if(mDept1.getSuperDeptId().equals(mDept12.getDeptId())){
                                mDept13=mDept1;
                            }
                        }
                        if(mDept13==null){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行五级机构层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行五级机构层级错误");
                        }
                        MDept mDept14=null;
                        for(MDept mDept1:mDept19){
                            if(mDept1.getSuperDeptId().equals(mDept13.getDeptId())){
                                mDept14=mDept1;
                            }
                        }
                        if(mDept14==null){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行六级机构层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行六级机构层级错误");
                        }
                        MDept mDept15=null;
                        for(MDept mDept1:mDept20){
                            if(mDept1.getSuperDeptId().equals(mDept14.getDeptId())){
                                mDept15=mDept1;
                            }
                        }
                        if(mDept15==null){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行七级机构层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行七级机构层级错误");
                        }
                        MDept mDept16=null;
                        for(MDept mDept1:mDept21){
                            if(mDept1.getSuperDeptId().equals(mDept15.getDeptId())){
                                mDept16=mDept1;
                            }
                        }
                        if(mDept16==null){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行八级机构层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行八级机构层级错误");
                        }

                        MDept mDept8=null;
                        for(MDept mDept1:mDept){
                            if(mDept1.getSuperDeptId().equals(mDept16.getDeptId())){
                                mDept8=mDept1;
                            }
                        }
                        if(mDept8==null){
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行九级机构层级错误");
                            throw new RuntimeException("第" + (i + 1) + "行九级机构层级错误");
                        }
                        List<MDept> mDept1 = mdeptService.getsonDept(mDept8.getDeptId());
                        if (mDept1.size() == 0 || mDept1 == null) {
                            mfeu.setDeptId(mDept8.getDeptId());
                        } else {
                            tidings.setStatus(Const.ERROR);
                            tidings.setMsg("第" + (i + 1) + "行请填写末级部门");
                            throw new RuntimeException("第" + (i + 1) + "行请填写末级部门");
                        }
                    }
                }else{
                    tidings.setStatus(Const.ERROR);
                    tidings.setMsg("第" + (i + 1) + "行请填写完整部门层级");
                    throw new RuntimeException("第" + (i + 1) + "行请填写完整部门层级");
                }
                String feeUserId = UuidUtil.getNumFormatUUID();
                mfeu.setFeeUserId(feeUserId);
                mfeu.setCreateDate(new Date());
                mfeu.setCorpId(cropId);
                mfeu.setStatus("1");
                mFeeUsers.add(mfeu);
            }
            if (mFeeUsers.size()>0) {
                for (MFeeUser mus : mFeeUsers) {
                    //后台添加缴费用户存入m_bind
                    feeUserService.saveFeeUserByExcel(mus);
                }
                tidings.setStatus(Const.SUCCESS);
                tidings.setMsg("导入"+mFeeUsers.size()+"行成功");
            }
        } catch (Exception e) {
            e.printStackTrace();
            if(tidings.getStatus()==null){
                tidings.setStatus(Const.ERROR);
                tidings.setMsg("导入失败，请按照模板填写数据");
            }
        }
        List<Tidings>list1=new ArrayList<Tidings>();
        this.getResponse().setContentType("text/html;charset=UTF-8");
        list1.add(tidings);
        try {
            this.getResponse().getWriter().write(JsonUtil.beanToJson(list1));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    @RequestMapping("/merchant/feeUserr/countUserNumber")
    @ResponseBody
    public Object gettUserNumber(Page page){
      Tidings<Object> tidings=new Tidings<Object>();
      PageData pd = this.getPageData();
      String startDate=pd.getString("startDate");//开始时间
      String endDate=pd.getString("endDate");//结束时间
        Date createDate=new Date();
        pd.put("createDate",createDate);//当前时间
      if (StringUtils.isNotBlank(startDate)){
          pd.put("startDate",startDate);
      }
      if(StringUtils.isNotBlank(endDate)){
          pd.put("endDate",endDate);
      }
      String status="1";//审批状态：1-生效 0-失效 2-审批中
        pd.put("status",status);
        page.setPd(pd);
        String corpId=this.getUser().getCorpId();//审批状态：1-生效 0-失效 2-审批中
        pd.put("corpId",corpId);
        page.setPd(pd);
        try {
            MFeeUser feeUser=feeUserService.getCountFeeUser(page);
            tidings.setT(feeUser).setPage(page);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return tidings;
    }
        /*
        *
        * 统计缴费用户数
        * */
    @RequestMapping("/merchant/feeUserr/getAllUserNumber")
    @ResponseBody
    public Object getAllUserNumber(Page page){
        Tidings<Object> tidings=new Tidings<Object>();
        PageData pd = this.getPageData();
        String status="1";//审批状态：1-生效 0-失效 2-审批中
        pd.put("status",status);
        page.setPd(pd);
        String corpId=this.getUser().getCorpId();//审批状态：1-生效 0-失效 2-审批中
        pd.put("corpId",corpId);
        page.setPd(pd);
        try {
            Integer number=feeUserService.getAllUserNumber(page);
            tidings.setT(number).setPage(page);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return tidings;
    }
        /*
        *
        * 当天新增缴费用户数
        * */
    @RequestMapping("/merchant/feeUserr/getTodayUserNumber")
    @ResponseBody
    public Object getTodayUserNumber(Page page){
        Tidings<Object> tidings=new Tidings<Object>();
        PageData pd = this.getPageData();
        Date createDate=new Date();
        pd.put("createDate",createDate);//当前时间
        String status="1";//审批状态：1-生效 0-失效 2-审批中
        pd.put("status",status);
        page.setPd(pd);
        String corpId=this.getUser().getCorpId();//审批状态：1-生效 0-失效 2-审批中
        pd.put("corpId",corpId);
        page.setPd(pd);
        try {
            Integer number=feeUserService.getTodayUserNumber(page);
            tidings.setT(number).setPage(page);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return tidings;
    }
}